package com.aube.guide;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.View;

import com.aube.R;
import com.aube.guide.views.DragGuideView;
import com.aube.guide.views.SwitchGuideView;
import com.aube.guide.views.VRGestureGuideView;
import com.aube.guide.views.VrMotionGuideView;
import com.aube.guide.views.ZoomInGuideView;

/**
 * Created by huyaonan on 16/6/22.
 */
public class GuideConstants {

    public static int DEFAULT_MASK_COLOR = 0x70000000;

    public static long DEFAULT_DELAY_MILLIS = 0;

    public static long DEFAULT_FADE_DURATION = 700;

    public static int DEFAULT_TARGET_PADDING = 0;

    public static int DEFAULT_COLOR_TEXTVIEW_INFO = 0xFF000000;

    public static int DEFAULT_DOT_SIZE = 55;

    public static int DEFAULT_AOTO_DISMISS_DURATION = 5000;
    public static int DEFAULT_DELAY_DURATION = 100;

    public static final String PLAY_SCALE = "PLAY_SCALE";
    public static final String PLAY_SWITCH = "PLAY_SWITCH";
    public static final String PLAY_DRAG = "PLAY_DRAG";
    public static final String PLAY_VR_GESTURE = "PLAY_VR_GESTURE";
    public static final String PLAY_VR_MOTION = "PLAY_VR_MOTION";

    private static PreferencesManager mPreferencesManager;

    public static void showScaleGuide(Activity activity, View view, OnGuidePerformedListener listener) {
        new ZoomInGuideView.Builder(activity)
                .setDelayMillis(DEFAULT_DELAY_DURATION)
                .enableFadeAnimation(true)
                .performClick(true)
                .setTarget(view)
                .setListener(listener)
                .setCanAudoDismiss(DEFAULT_AOTO_DISMISS_DURATION)
                .setUsageId(GuideConstants.PLAY_SCALE)
                .setImageRes(R.drawable.guide_scale)
                .setMaskColor(Color.TRANSPARENT)
                .show();
    }

    public static boolean showSwitchGuide(Activity activity, View view, OnGuidePerformedListener listener) {
        if(isSwitchGuideShowed(activity))
            return false;
        new SwitchGuideView.Builder(activity)
                .setDelayMillis(DEFAULT_DELAY_DURATION)
                .enableFadeAnimation(true)
                .performClick(true)
                .setTarget(view)
                .setListener(listener)
                .setCanAudoDismiss(DEFAULT_AOTO_DISMISS_DURATION)
                .setUsageId(GuideConstants.PLAY_SWITCH)
                .setImageRes(R.drawable.guide_touch)
                .show();
        return true;
    }

    public static void showDragGuide(Activity activity, View target, View main, OnGuidePerformedListener listener) {
        if(isDragGuideShowed(activity))
            return;
        new DragGuideView.Builder(activity)
                .setDelayMillis(DEFAULT_DELAY_DURATION)
                .enableFadeAnimation(true)
                .performClick(true)
                .setTarget(target)
                .setMainView(main)
                .setListener(listener)
                .setCanAudoDismiss(DEFAULT_AOTO_DISMISS_DURATION)
                .setUsageId(GuideConstants.PLAY_DRAG)
                .setImageRes(R.drawable.guide_move)
                .show();
    }

    public static void showVrGuide(Activity activity, View target, boolean motionGuide, OnGuidePerformedListener listener) {
        if(motionGuide)
            GuideConstants.showVrMotionGuide(activity, target, listener);
        else
            GuideConstants.showVrGestureGuide(activity, target, listener);
    }

    private static void showVrGestureGuide(Activity activity, View target, OnGuidePerformedListener listener) {
        new VRGestureGuideView.Builder(activity)
                .setDelayMillis(DEFAULT_DELAY_DURATION)
                .enableFadeAnimation(true)
                .performClick(true)
                .setTarget(target)
                .setListener(listener)
                .setCanAudoDismiss(DEFAULT_AOTO_DISMISS_DURATION)
                .setUsageId(GuideConstants.PLAY_VR_GESTURE)
                .setImageRes(R.drawable.guide_vr)
                .show();
    }

    private static void showVrMotionGuide(Activity activity, View target, OnGuidePerformedListener listener) {
        new VrMotionGuideView.Builder(activity)
                .setDelayMillis(DEFAULT_DELAY_DURATION)
                .enableFadeAnimation(true)
                .performClick(true)
                .setTarget(target)
                .setListener(listener)
                .setCanAudoDismiss(DEFAULT_AOTO_DISMISS_DURATION)
                .setUsageId(GuideConstants.PLAY_VR_MOTION)
                .show();
    }

    public static boolean isScaleGuideShowed(Context context) {
        return isGuideShowed(context, PLAY_SCALE);
    }

    public static void scaleGuidePerformed(Context context) {
        guidePerformed(context, PLAY_SCALE);
    }

    public static boolean isSwitchGuideShowed(Context context) {
        return isGuideShowed(context, PLAY_SWITCH);
    }

    public static void switchGuidePerformed(Context context) {
        guidePerformed(context, PLAY_SWITCH);
    }

    public static boolean isDragGuideShowed(Context context) {
        return isGuideShowed(context, PLAY_DRAG);
    }

    public static void dragGuidePerformed(Context context) {
        guidePerformed(context, PLAY_DRAG);
    }

    public static void vrGestureGuidePerformed(Context context) {
        guidePerformed(context, PLAY_VR_GESTURE);
    }

    public static void vrMotionGuidePerformed(Context context) {
        guidePerformed(context, PLAY_VR_MOTION);
    }

    public static boolean isGuideShowed(Context context, String id) {
        if(mPreferencesManager == null)
            mPreferencesManager = new PreferencesManager(context.getApplicationContext());
        return mPreferencesManager.isDisplayed(id);
    }

    public static void guidePerformed(Context context, String id) {
        if(mPreferencesManager == null)
            mPreferencesManager = new PreferencesManager(context.getApplicationContext());
        mPreferencesManager.setDisplayed(id);
    }

}
